package com.snailhd.framework.common.util;

import com.snailhd.framework.common.entity.PageData;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页对象生成
 * @author snailhd
 */
public class QueryPageUtil {

    public static <T> PageData<T> query(
            Executor<Long> totalFunction,
            Executor<List<T>> dataFunction){
        Long total = totalFunction.exec();
        List<T> list;
        if(total>0){
            list = dataFunction.exec();
        }else{
            list = new ArrayList<>(0);
        }
        return new PageData<>(total,list);
    }

    public interface Executor<T>{
        T exec();
    }


}
